home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / tkern10.zip / INCLUDE\SYS\TASK.H < prev    next >
Text File  |  1994-07-03  |  3KB  |  85 lines

  1. /*
  2.  *  This file forms part of "TKERN" - "Troy's Kernel for Windows".
  3.  *
  4.  *  Copyright (C) 1994  Troy Rollo <troy@cbme.unsw.EDU.AU>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef __task_h
  22. #define __task_h
  23.  
  24. #define    UFILE_MAX    20
  25. #define    TNTASK        20 /* Total number of tasks */
  26.  
  27. #define    HTASK_FLEDGELING    ((HTASK) -1)
  28.  
  29. struct    task
  30. {
  31.     HTASK    hTask;
  32.     short    pid;
  33.     int    iFledgeling;    /* For our fork()            */
  34.     int    iParent;    /* For easy reference during fork/exec    */
  35.     int    nChildren;    /* Number of children executed        */
  36.     int    nZombies;    /* Number of zombies waiting for reaping */
  37.     HFILE    files[UFILE_MAX];
  38.     char    **argv;
  39.     char    **envp;
  40.     unsigned nFlags;
  41.     int    nError;
  42.     int    nSignal;
  43.     char    *pchCreatedBy;
  44.     void far pascal (*intrproc)(int); /* Call this to deliver signals */
  45. };
  46.  
  47. #define    TF_ASLEEP    1    /* Task is sleeping        */
  48. #define    TF_EXEC        2    /* Task is execing a child    */
  49.  
  50. /* An MS-Windows TASK handle is almost, but not quite, entirely unlike a process ID.
  51.  * While the task is running, it uniquely identifies the task. The difference is, if
  52.  * the parent process isn't careful, the task may terminate, and a new one may be
  53.  * started with the same task handle. We need to have the parent task being capable
  54.  * of knowing when its children die. Consequently, we need to keep a record of all
  55.  * processes entering and leaving the system. If the process in question was started
  56.  * using tkexec, and it exits it becomes a zombie until the parent waits for it.
  57.  *
  58.  * If the parent exits first, its parent pid becomes 1 (the process 1 doesn't exist,
  59.  * but this mirrors Ken's OS), its parent hTask becomes 0, and the process is reaped
  60.  * automatically on exit. This is getting scarily close to POSIX realities.
  61.  *
  62.  * Valid task handles are 2-32767. If a process exits while its child still lives,
  63.  * the child is reaped on exit. Essentially, we try to maintain parent-child
  64.  * relationships even though windows itself doesn't.
  65.  *
  66.  * We cannot maintain parent-child relationships if the child is WinExec'd. See
  67.  * tkern.c for the reasoning. I think the cause is a Windows bug (gasp).
  68.  *
  69.  * One wonders why NT doesn't do something like this.
  70.  */
  71.  
  72. struct    tk_process
  73. {
  74.     short    pid;        /* 0 for an empty entry                    */
  75.     short    pidParent;    /* 1 for a task without a parent            */
  76.     HTASK    hTask;        /* 0 for a zombie                    */
  77.     HTASK    hTaskParent;    /* 0 for a task without a parent            */
  78.     int    iParent;    /* -1 if the parent wasn't tkexec'd            */
  79.     int    nRetCode;    /* Return code of the program                */
  80. };
  81.  
  82. #define    N_TKPROCS    100    /* If we exceed this, we are in deep benji by-product    */
  83.  
  84. #endif /* __task_h */
  85.